#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode *next;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

class symmetricTree {
public:
    // 递归比较left->left和right->right以及left->right和right->left，本质是前序遍历
    bool isSymmetric(TreeNode* root) {
        if (root == NULL) 
            return true;
        return recur(root->left, root->right);
    }

    bool recur(TreeNode* left, TreeNode* right) {
        if (!left && !right)
            return true;
        if (left == NULL || right == NULL || left->val != right->val)
            return false;
        return recur(left->left, right->right) && recur(left->right, right->left);
    }
};